package com.example.javaspringbootdemo;

import org.junit.jupiter.api.Test;
import java.util.Arrays;

public class ArrayOpera {

    // 冒泡排序
    @Test
    public void maoPao(){
        int[] arr = new int[]{10,1,35,61,89,36,55};
        for (int i = 0; i< arr.length -1 ; i++ ){
            for (int j = 0; j< arr.length - i - 1;j++){
                if (arr[j]<arr[j+1]){
                    int n = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = n;
                }
            }
        }
        for (int i : arr){
            System.out.println(i);
        }
    }
    //系统自动的排序
    @Test
    public void  testSort(){
        int[] arr = new int[]{10,1,35,61,89,36,55};
        Arrays.sort(arr);
        for (int i : arr){
            System.out.println(i);
        }
    }

    //二维数组,打印
    @Test
    public  void  erWeiArray(){
        int[][] arr  ={
                {1,2,2},
                {3,5,6,7}
        };
        System.out.println(Arrays.deepToString(arr));

    }

    //字符串
    @Test
    public void testString(){
        String s1 = "hello";
        String s2 = "hEllo";
        System.out.println(s1.equals(s2));
        System.out.println(s1.equalsIgnoreCase(s2)); //忽略大小写
        System.out.println(s1.contains("e"));// 是否包含子串
        System.out.println("----搜索子串的更多的例子-----");
        System.out.println(s1.indexOf("l")); //2
        System.out.println(s1.lastIndexOf("l")); // 3
        System.out.println(s1.startsWith("he")); //true
        System.out.println(s1.endsWith("lo"));   // true
        System.out.println("------提取子串的例子-------");
        System.out.println(s1.substring(2)); //llo
        System.out.println(s1.substring(2,4)); //ll
        System.out.println("-----去除首尾空白字符------");
        System.out.println(s1.trim());





    }
}
